home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Utilities / HDF Utilities < prev    next >
Text File  |  1996-01-29  |  7KB  |  309 lines

  1. ||
  2. ||*******************************************************************
  3. || 
  4.  
  5. Macro ReadAllHDFRaster8()
  6.     SetHDFSource()
  7.     if(strlen(gHDF_src_file)==0)
  8.         return
  9.     endif
  10.     
  11.     PauseUpdate; silent 1
  12.     variable i=0
  13.     variable num
  14.     String     theImage,baseName="Image",paletteRefs="palettes"
  15.     make/o    theCtab
  16.     
  17.     | Get a list of reference number for the raster8 images in the file 
  18.     HDFInfo mode=5,tag=202,gHDF_src_file
  19.     
  20.     | Move the list to a local wave in case the default wave gets overwritten later
  21.     Duplicate/o hdf_list,refsList
  22.  
  23.     num=numPnts(refsList)                    | find the number of raster8 pictures in the file
  24.     
  25.     do
  26.         theImage=baseName+num2str(i)        | build a name for the image wave
  27.         Make /o $theImage
  28.         HDFInfo mode=256,ref=refsList[i],tag=201,gHDF_src_file
  29.         
  30.         if(hdf_flag==1)                        | if there was no error in reading the image
  31.         
  32.             hdfReadImage ref=refsList[i],IMAGENAME=$theImage,PALNAME=theCtab,gHDF_src_file
  33.             HDFInfo     Image8Dim,ref=refsList[i],tag=202,gHDF_src_file
  34.             
  35.             display;                                | create a window and set its size for the image
  36.             ModifyGraph width=hdf_image_width,height=hdf_image_height
  37.              appendimage $theImage                
  38.             modifyimage $theImage cindex=theCtab
  39.             
  40.         else                                        | if there are no color palettes
  41.             hdfReadImage ref=refsList[i],imagename=$theImage,gHDF_src_file
  42.             display; appendimage $theImage
  43.         endif
  44.         i+=1
  45.     while(i<num)
  46.     
  47.     KillStrings gHDF_src_file,gHDF_src_path
  48.     TileWindows/O=1 Graph1
  49. end
  50.  
  51. ||
  52. ||    Display specified images from an HDF file
  53. ||    
  54.  
  55. Macro DisplayHDFImages()
  56.  
  57.     SetHDFSource()
  58.     if(strlen(gHDF_src_file)==0)
  59.         return
  60.     endif
  61.  
  62.     PauseUpdate; silent 1
  63.     Variable/G    gImageIndex=1
  64.     String/G    gRefList
  65.     
  66.     |  Before we ask for the reference number we find which references are in the specified
  67.     |  file.  The references are stored into a wave HDF_List which we will convert into
  68.     |  a global string to be used in getImageIndex()
  69.     
  70.     if(Exists("HDF_List"))
  71.         KillWaves HDF_List
  72.     endif
  73.     
  74.     HDFInfo mode=5,tag=202,gHDF_src_file
  75.     if(numpnts(HDF_List)<1)
  76.         print  "There are no raster8 images in this file"
  77.     else
  78.         gRefList=wave2String(HDF_List)
  79.         if(strlen(gRefList)>0)
  80.             getImageIndex()
  81.             
  82.             if(gImageIndex>0)
  83.                 Hdfreadimage/P=$gHDF_src_path     ref=gImageIndex,imageName=jj,gHDF_src_file
  84.                 HDFreadImage/P=$gHDF_src_path     ref=gImageIndex,Mode=16,palname=jp,gHDF_src_file
  85.                 HDFInfo/P=$gHDF_src_path         Image8Dim,ref=gImageIndex,tag=202,gHDF_src_file
  86.                 
  87.                 display; 
  88.                 ModifyGraph     width=hdf_image_width,height=hdf_image_height
  89.                 appendimage jj; modifyimage jj cindex=jp;
  90.             endif
  91.         else
  92.             print "There are no raster8 images in this file"
  93.         endif
  94.     endif
  95.     
  96.     |  cleanup name space
  97.     KillVariables gImageIndex
  98.     KillStrings gRefList
  99. end
  100.  
  101. ||
  102. ||*******************************************************************
  103. ||
  104.  
  105. Proc getImageIndex(indexStr)
  106.     String indexStr
  107.     prompt indexStr,"References:" ,popup,gRefList
  108.     Variable index=str2num(indexStr)
  109.     gImageIndex=index
  110. end
  111.  
  112.  
  113. ||
  114. ||*******************************************************************
  115. ||
  116.  
  117.  
  118.  
  119. Macro Translate_Tags(tagID)
  120.     Variable tagID=0;
  121.     prompt tagID,"Tag Number:"
  122.     
  123.     HDFInfo tag2text=tagID
  124. end
  125.  
  126. ||
  127. ||    The following proc gets from the user the path and the file name for the HDF source
  128. ||
  129. || 
  130.  
  131. Proc SetHDFSource(pathName, srcFile)
  132.     String pathName
  133.     Prompt pathName "Symbolic Path", popup "_Create New Path_;" + PathList("*",";","")
  134.     String srcFile
  135.     Prompt srcFile,"File name or \"\" to choose file from a dialog"
  136.     PauseUpdate;silent 1
  137.     Variable dummyFileRefNum
  138.     String/G  gHDF_src_file,gHDF_src_path
  139.     
  140.     gHDF_src_path=pathName
  141.     if ((strlen(pathName)==0) %| (CmpStr(pathName, "_Create New Path_")==0))
  142.         NewPath/O hdfPath
  143.         gHDF_src_path = "hdfPath"
  144.     endif
  145.     
  146.     if (strlen(srcFile)==0)
  147.         Open/R/D/T="????"/P=$gHDF_src_path/M="Choose an HDF file" dummyFileRefNum
  148.         gHDF_src_file = S_fileName
  149.     endif
  150.     
  151. end
  152.  
  153. ||
  154. ||*******************************************************************
  155. ||
  156.  
  157. Function/S wave2string(w)
  158.     Wave w
  159.     
  160.     PauseUpdate; silent 1
  161.     Variable num=numpnts(w)
  162.     Variable i=0
  163.     String    str="",tmp=""
  164.         
  165.     do
  166.         if(w[i]<1)                                // allow only valid reference values
  167.             return tmp
  168.         endif
  169.         str=str+num2str(w[i])+";"
  170.         i+=1
  171.     while(i<num)
  172.  
  173.     return str
  174. end
  175.  
  176. ||
  177. ||*******************************************************************
  178. ||
  179.  
  180. Macro ReadHDFSDS()
  181.  
  182.     SetHDFSource()
  183.     if(strlen(gHDF_src_file)==0)
  184.         return
  185.     endif
  186.  
  187.     PauseUpdate; silent 1
  188.     Variable/G    gImageIndex=1
  189.     String/G    gRefList
  190.     
  191.     |  Before we ask for the reference number we find which references are in the specified
  192.     |  file.  The references are stored into a wave HDF_List which we will convert into
  193.     |  a global string to be used in getImageIndex()
  194.     
  195.     if(Exists("HDF_List"))
  196.         KillWaves HDF_List
  197.     endif
  198.     
  199.     HDFInfo        ListSDS,mode=4,gHDF_src_file
  200.     
  201.     if(numpnts(HDF_List)<1)
  202.         print  "There are no SDS objects in this file"
  203.     else
  204.         gRefList=wave2String(HDF_List)
  205.         if(strlen(gRefList)>0)
  206.             getImageIndex()
  207.             
  208.             if(gImageIndex>0)
  209.                 HDFReadSDS Ref=gImageIndex,gHDF_src_file
  210.             endif
  211.         else
  212.             print "There are no SDS objects in this file"
  213.         endif
  214.     endif
  215.     
  216.     |  cleanup name space
  217.     KillVariables gImageIndex
  218.     KillStrings gRefList
  219. end
  220.  
  221. ||
  222. ||*******************************************************************
  223. ||
  224.  
  225. Macro ListHDFVgroups()
  226.  
  227.     SetHDFSource()
  228.     if(strlen(gHDF_src_file)==0)
  229.         return
  230.     endif
  231.     
  232.     PauseUpdate; silent 1
  233.     HDFInfo vgroupsrefs,gHDF_src_file
  234.     Variable numRefs=numpnts(HDF_VGroupRefs)
  235.     if(numRefs>0)
  236.         print "Group Name        No. of objects"
  237.         Variable i=0
  238.         do
  239.             HDFInfo VGroupName,ref=HDF_VGroupRefs[i], gHDF_src_file
  240.             HDFInfo ref=HDF_VGroupRefs[i],numvobjects, gHDF_src_file
  241.             printf "%d)  %s:\t\t%d\r",i+1, HDF_VGroupName,HDF_NumVObjects
  242.             i+=1
  243.         while(i<numRefs)
  244.         
  245.         KillStrings gHDF_src_file,gHDF_src_path,HDF_VGroupName
  246.         KillVariables HDF_NumVObjects
  247.     endif
  248.     KillWaves HDF_VGroupRefs
  249. end
  250.  
  251. ||
  252. ||*******************************************************************
  253. ||
  254.  
  255. Macro HDFsdsInfo()
  256.  
  257.     SetHDFSource()
  258.     if(strlen(gHDF_src_file)==0)
  259.         return
  260.     endif
  261.     
  262.     PauseUpdate; silent 1
  263.     
  264.     HDFInfo ListSDS,mode=4,gHDF_src_file
  265.     Variable numRefs=numpnts(HDF_List)
  266.     if(numRefs>0)
  267.         Variable/G    gImageIndex=1
  268.         String/G    gRefList
  269.         
  270.         gRefList=wave2String(HDF_List)
  271.         if(strlen(gRefList)>0)
  272.             getImageIndex()
  273.             if(gImageIndex>0)
  274.                 if(Exists("HDF_SDS_Max"))
  275.                     KillVariables HDF_SDS_Max,HDF_SDS_Min,HDF_SDS_Fill
  276.                 endif
  277.                 if(Exists("HDF_SDS_Cal"))
  278.                     KillVariables HDF_SDS_Cal,HDF_SDS_CalError,HDF_SDS_CalOffset
  279.                 endif
  280.                 HDFInfo SDSInfo,SDSRange,SDSCal,ref=gImageIndex,gHDF_src_file
  281.                 printf "SDS Information for reference %g:\r",gImageIndex
  282.                 printf "\tRank=%g\t HDF Number type=%g Number of sets=%g\r",HDF_SDS_Rank,HDF_SDS_NumType,HDF_SDS_NumSets
  283.                 KillVariables HDF_SDS_Rank,HDF_SDS_NumType,HDF_SDS_NumSets
  284.                 if(Exists("HDF_SDS_Max"))
  285.                     printf "\tRange: \t Max=%g\tMin=%g\tFill=%g\r" HDF_SDS_Max,HDF_SDS_Min,HDF_SDS_Fill
  286.                     KillVariables HDF_SDS_Max,HDF_SDS_Min,HDF_SDS_Fill
  287.                 endif
  288.                 if(Exists("HDF_SDS_Cal"))
  289.                     printf "\tCalibration:\t Cal=%g\tcal_error=%gcal_offset=%g\tcal_offset_error=%g\r", HDF_SDS_Cal,HDF_SDS_CalError,HDF_SDS_CalOffset,HDF_SDS_CalOffsetError
  290.                     KillVariables HDF_SDS_Cal,HDF_SDS_CalError,HDF_SDS_CalOffset
  291.                 endif
  292.             else
  293.                 print "Could not find specified SDS"
  294.             endif
  295.         else
  296.             print "Could not find specified SDS"
  297.         endif
  298.     endif
  299.     
  300.     KillWaves HDF_List
  301.     KillStrings gHDF_src_file,gHDF_src_path
  302. end
  303.  
  304. ||
  305. ||*******************************************************************
  306. ||
  307.  
  308.  
  309.